package com.rundatop.wx.service.impl;

import org.springframework.stereotype.Service;

import java.io.Serializable;
import java.util.List;
import javax.annotation.Resource;

import com.github.pagehelper.PageHelper;
import com.google.common.collect.Lists;
import com.rundatop.dao.mapper.CitiesMapper;
import com.rundatop.dao.model.Cities;
import com.rundatop.dao.model.User;
import com.rundatop.wx.dto.Page;
import com.rundatop.wx.service.CitiesService;

import tk.mybatis.mapper.entity.Example;

/**
* 通用 Mapper 代码生成器
*
* @author mapper-generator
*/
@Service
public class CitiesServiceImpl extends BaseService<Cities> implements CitiesService{
	
	@Resource
    private CitiesMapper citiesMapper;

    @Override
    public int add(Cities entity, User loginUser) {

        //if (isBlank(entity.getCode())) {
        //    throw new BusinessException("代码不能为空");
        //}

       return citiesMapper.insertSelective(entity);
    }

    @Override
    public int edit(Cities entity, User loginUser) {

        //if (isBlank(entity.getId())) {
        //    throw new BusinessException("Id不能为空");
        //}

        return citiesMapper.updateByPrimaryKeySelective(entity);
    }

    @Override
    public int deleteById(Serializable id, User loginUser) {
       return citiesMapper.deleteByPrimaryKey(id);
    }

    @Override
    public List<Cities> getList(Cities condition, Page page, User loginUser) {
        Example ex = new Example(Cities.class);

        Example.Criteria c = ex.createCriteria();

        //if (isNotBlank(condition.getCode())) {
        //    c.andEqualTo("code", condition.getCode());
        //}

        //if (isNotBlank(condition.getName())) {
        //    c.andLike("name", fullLike(condition.getName()));
        //}

        //ex.orderBy("code").asc();

        if (page != null) {
            PageHelper.startPage(page.getPage(), page.getRows());
        }

        List<Cities> list = citiesMapper.selectByExample(ex);
        return list;
    }

    @Override
    public Cities getById(Serializable id) {
        return citiesMapper.selectByPrimaryKey(id);
    }
}




